//
//  RSWDataOperation+AddressBookContact.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 16/12/29.
//  Copyright © 2016年 com.xtion.crm. All rights reserved.
//

#import "RSWDataOperation+AddressBookContact.h"
#import "RSWRESTService+AddressBookContact.h"

@implementation RSWDataOperation (AddressBookContact)

-(void)getCommonAddressBookContactListCompletion:(void (^)(NSInteger, XMSQueueDictionary *,NSError *error))completion
{
    EDOMRequestStateType stateType =
    [super requestAsyncBlock:^
     {
         __block NSInteger thisnResult = FALSE;
         __block NSArray *thisList = nil;
         __block NSError *thisError = nil;
         
         RSWRESTService *ser = [[RSWRESTService alloc]initWithDataOperationManagerDelegate:nil AttachDOM:self];
         NSString *token = [XLGContext context].m_token;
         
         XLGResult *r = [ser getCommonAddressBookContact:token];
         thisnResult = r.outResult;
         thisList = r.outObj;
         thisError = r.outError;
         
         XMSQueueDictionary *thisDic = nil;
         if(thisnResult == YES)
         {
             thisDic = [self groupBySortPinyinPorperty:thisList];
         }
         
         [super requestResult:thisnResult output:thisDic error:nil completion:^(NSInteger nResult, id output, NSError *error)
          {
              completion(thisnResult,thisDic,error);
          }];
     }];
    if(stateType == EDOMRequestStateTypeCanNotRequest)
        completion(TERMINATEREADWRITE,nil,nil);
}

-(void)getPrivateAddressBookContactListCompletion:(void (^)(NSInteger, XMSQueueDictionary *,NSError *error))completion
{
    EDOMRequestStateType stateType =
    [super requestAsyncBlock:^
     {
         __block NSInteger thisnResult = FALSE;
         __block NSArray *thisList = nil;
         __block NSError *thisError = nil;
         
         RSWRESTService *ser = [[RSWRESTService alloc]initWithDataOperationManagerDelegate:nil AttachDOM:self];
         NSString *token = [XLGContext context].m_token;
         
         XLGResult *r = [ser getPrivateAddressBookContact:token];
         thisnResult = r.outResult;
         thisList = r.outObj;
         thisError = r.outError;
         
         XMSQueueDictionary *thisDic = nil;
         if(thisnResult == YES)
         {
             thisDic = [self groupBySortPinyinPorperty:thisList];
         }

         [super requestResult:thisnResult output:thisDic error:nil completion:^(NSInteger nResult, id output, NSError *error)
          {
              completion(thisnResult,thisDic,error);
          }];
     }];
    if(stateType == EDOMRequestStateTypeCanNotRequest)
        completion(TERMINATEREADWRITE,nil,nil);
}

@end
